
from generate_panel_image import PanelImage
from custom_logger import PrefixDateLogger
from email_send import  SendEmail
from monitor_hour_data import HourData
import time  # 导入time模块，用于添加延迟
# -------------------------- 配置参数（必须修改）--------------------------

# ------------------------------------------------------------------------
logger = PrefixDateLogger("send_monitor_hour_email")
# 执行脚本
if __name__ == "__main__":
    # 创建连接实例
    panel_image = PanelImage()
    email=SendEmail()
    hour_object = HourData()

    update_data=hour_object.gen_update_time_table()
    days_data=hour_object.gen_days_compare_table()

    hour_data=hour_object.gen_active_final_hour_table()

    logger.info(f"update_time:{update_data}")

    image_path = panel_image.general_image("adtb6zh",
                                           "ff617fd",
                                           None,
                                           1600)

    #image_path='/home/cys/www/script/notification_data/screenshot/ff617fd_2025-11-12_18-31-31.png'
    logger.info(f"image_path:{image_path}")
    if image_path:

        title="监控主动活跃小时数据"
        # 邮件正文（支持HTML）
        body = f"""
        
        <h2>{update_data[0]}：</h2>
        <p>{update_data[1]}</p>
        
        <h2>{days_data[0]}：</h2>
        <p>{days_data[1]}</p>
         <p>{days_data[2]}</p>
         
         <h2>{hour_data[0]}：</h2>
        <p>{hour_data[1]}</p>
         <p>{hour_data[2]}</p>
        <p>附件为仪表盘截图</p>
        """
        if update_data[2] or days_data[3] or hour_data[3]:
            title="⚠️【告警】主动活跃小时数据"

        email.send_email_with_attachment(title,body,image_path)
